package com.myfum.wingplayer.components.ui
{
	import com.myfum.wingplayer.entity.ProgramData;
	import com.myfum.wingplayer.entity.ProjectData;
	import com.myfum.wingplayer.entity.RegionData;
	
	import flash.events.Event;
	import flash.net.URLRequest;
	
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	import mx.events.ResizeEvent;
	
	public class Program extends UIComponent
	{
		private var _data:ProgramData;
		private var _container:UIComponent;
		
		public function Program()
		{
			super();
			init();
			configListeners();
		}
		
		private function init():void{
			_container = new UIComponent();
			addChild(_container);
		}
		
		private function configListeners():void{
//			FlexGlobals.topLevelApplication.addEventListener(ResizeEvent.RESIZE, onResize);
		}
		
		/*private function onResize(evt:ResizeEvent):void{
			this.width = FlexGlobals.topLevelApplication.width;
			this.height = FlexGlobals.topLevelApplication.height;
		}*/
		
		private function placeRegions():void{
			for(var i:int = 0;i<data.arrayCollection.length;i++){
				var r:Region = new Region(data.audiofrom != data.arrayCollection.getItemAt(i).name);
				r.data = data.arrayCollection.getItemAt(i) as RegionData;
				_container.addChild(r);
			}
		}

		public function get data():ProgramData
		{
			return _data;
		}

		public function set data(value:ProgramData):void
		{
			_data = value;
			dispose();
			placeRegions();
		}
		
		public function dispose():void{
//			FlexGlobals.topLevelApplication.removeEventListener(ResizeEvent.RESIZE, onResize);
			while(_container.numChildren > 0){
				var region:Region = _container.removeChildAt(0) as Region;
				region.dispose();
				region = null;
			}
		}
		
	}
}